/* 
 * File:   planttest.cpp
 * Author: dolphinigle
 *
 * Created on March 12, 2011, 7:13 PM
 */

#include <stdlib.h>
#include "gtest/gtest.h"
#include "direction.hpp"
#include "plantablecell.hpp"
#include "plantconstants.hpp"
#include "fruit.hpp"
#include "game.hpp"

Fruit* harvest();
  bool isHarvestable();
  void advanceDay();
  void advanceTime();
  bool isDead();
  bool isMature();
  bool isSteppable();

TEST(PlantTest, All) {

  /*for (int k = 0; k < PlantConstants::getPlantCount(); ++k) {

    Game* game = new Game("Irvan", "test.gag");

    Plant* plant = new Plant(game, 
            dynamic_cast<PlantableCell* >
                (game->getMaps()->getField()->getCellAt(2,2)),
            k);

    game->getCreatures()->getPlants()->addPlant(plant);

    PlantableCell* pc = dynamic_cast<PlantableCell* >
            (game->getMaps()->getField()->getCellAt(2,2));

    EXPECT_EQ(plant->getId(), k);

    for (int i = 0; i < PlantConstants::getPlantMatureTime(k) * 10; ++i) {
      EXPECT_TRUE(plant->isSteppable() || plant->isDead());
      EXPECT_FALSE(plant->isMature());
      EXPECT_TRUE(plant->isSeed() || plant->isDead());
      EXPECT_FALSE(plant->isHarvestable());
      plant->advanceDay();
    }

    pc->water();

    for (int i = 0; i < PlantConstants::getPlantMatureTime(k); ++i) {
      EXPECT_TRUE(plant->isSteppable() || plant->isDead());
      EXPECT_FALSE(plant->isMature());
      EXPECT_TRUE(plant->isSeed() || plant->isDead());
      EXPECT_FALSE(plant->isHarvestable());
      plant->advanceDay();
    }

    EXPECT_FALSE(plant->isSteppable());
      EXPECT_TRUE(plant->isMature() || plant->isDead());
    EXPECT_FALSE(plant->isSeed());
    EXPECT_FALSE(plant->isHarvestable());

    pc->advanceDay();

    for (int i = 0; i < PlantConstants::getPlantRipeTime(k, 0) * 10; ++i) {
      EXPECT_FALSE(plant->isSteppable());
      EXPECT_TRUE(plant->isMature() || plant->isDead());
      EXPECT_FALSE(plant->isSeed());
      EXPECT_FALSE(plant->isHarvestable());
      plant->advanceDay();
    }

    pc->water();

    for (int i = 0; i < PlantConstants::getPlantRipeTime(k, 0); ++i) {
      EXPECT_FALSE(plant->isSteppable());
      EXPECT_TRUE(plant->isMature() || plant->isDead());
      EXPECT_FALSE(plant->isSeed());
      EXPECT_FALSE(plant->isHarvestable());
      plant->advanceDay();
    }

    EXPECT_FALSE(plant->isSteppable());
    EXPECT_TRUE(plant->isMature() || plant->isDead());
    EXPECT_FALSE(plant->isSeed());
    EXPECT_TRUE(plant->isHarvestable() || plant->isDead());
    Fruit* res;
    if (plant->isHarvestable()) {
      res = plant->harvest();
      EXPECT_EQ(res->getId(), PlantConstants::getFruitId(k));
      delete res;
    }

    if (PlantConstants::getPlantHarvestType(k) == kMultipleHarvest) {
      EXPECT_FALSE(plant->isSteppable());
      EXPECT_TRUE(plant->isMature() || plant->isDead());
      EXPECT_FALSE(plant->isSeed());
      EXPECT_FALSE(plant->isHarvestable());

      for (int j = 1; j <= 10; ++j) {
        for (int i = 0; i < PlantConstants::getPlantRipeTime(k, j); ++i) {
          EXPECT_FALSE(plant->isSteppable());
          EXPECT_TRUE(plant->isMature() || plant->isDead());
          EXPECT_FALSE(plant->isSeed());
          EXPECT_FALSE(plant->isHarvestable());
          plant->advanceDay();
        }

        EXPECT_FALSE(plant->isSteppable());
        EXPECT_TRUE(plant->isMature() || plant->isDead());
        EXPECT_FALSE(plant->isSeed());
        EXPECT_TRUE(plant->isHarvestable() || plant->isDead());

        if (plant->isHarvestable()) {
          res = plant->harvest();
          EXPECT_EQ(res->getId(), PlantConstants::getFruitId(k));
          delete res;
        }
      }

    } else {
      EXPECT_TRUE(!game->getCreatures()->getPlants()->containsPlantAt(pc) || plant->isDead());
    }

    Plant* p2 = new Plant(game,
            dynamic_cast<PlantableCell* >
                (game->getMaps()->getField()->getCellAt(2,2)),
            k);
    p2->makeHarvestable();
    EXPECT_TRUE(p2->isMature());
    EXPECT_TRUE(p2->isHarvestable());

    p2->makeDead();
    EXPECT_TRUE(p2->isDead());
    EXPECT_FALSE(p2->isHarvestable());

    p2->restartToSeed();
    EXPECT_TRUE(p2->isSeed());
    EXPECT_FALSE(p2->isHarvestable());

    delete game;
  }*/
}

